package com.zookeeper.zktest;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.util.concurrent.CountDownLatch;

/**
 * @Author : hebad90@163.com
 * @Date : 2014/11/18 22:47
 * @From : javalearn
 */
public class Test implements Watcher {
    public static void main(String[] args) throws Exception {
        new Test();
        CountDownLatch latch = new CountDownLatch(1);
        latch.await();
    }

    private ZooKeeper zk;

    public Test() throws Exception {
        zk = new ZooKeeper("localhost:2181", 1000, this);
    }

    public void process(WatchedEvent e) {
        System.out.println(e.getType());
        try {
            byte[] bs = zk.getData("/test/leader", true, null);
            System.out.println(bs);
        } catch (KeeperException e1) {
            e1.printStackTrace();
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
    }
}
